package com.gwd.task.model;

import cn.hutool.core.bean.BeanUtil;
import com.gwd.task.entity.ProjectModuleEntity;
import lombok.Data;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.util.ArrayList;
import java.util.List;

/**
 * @author zhiyongming
 * @date 2020/11/19 19:01
 */
@Data
public class ProjectModuleDTO {
    @NotNull(message = "模块id不能为空")
    private Long moduleId;
    private Long superior;
    private Long groupId;
    private Long projectId;
    @NotBlank(message = "模块名称不能为空")
    private String moduleName;

    private List<ProjectModuleDTO> children;
    private List<TaskDTO> tasks;

    public ProjectModuleDTO() {}
    public ProjectModuleDTO(ProjectModuleEntity entity) {
        BeanUtil.copyProperties(entity, this);
    }
    public void addChildren(ProjectModuleDTO dto) {
        if (this.children==null) {
            this.children = new ArrayList<>();
        }
        this.children.add(dto);
    }
    public void addTask(TaskDTO dto) {
        if (this.tasks==null) {
            this.tasks = new ArrayList<>();
        }
        this.tasks.add(dto);
    }

}
